package hot;

import java.util.HashMap;
import java.util.HashSet;

/**
 * @author way
 * @create 2025-03-03 20:20
 */
public class _128_longestConsecutive {
    public int longestConsecutive(int[] nums) {
        HashSet<Integer> set = new HashSet<>();
        int res = 0;
        for (int num : nums) {
            set.add(num);
        }

        for (int x : set) {
            if (set.contains(x - 1)) continue;

            int y = x + 1;
            while (set.contains(y)) {
                y++;
            }

            res = Math.max(res, y - x);
        }
        return res;
    }
}
